package com.yq.day30.udp1.v3;

import com.yq.utils.NetUtils;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.Scanner;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/30 16:55
 */
public class Demo02 {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(9999);
        Scanner scanner = new Scanner(System.in);
        while (true){
            DatagramPacket receivePacket = NetUtils.getReceivePacket();
            socket.receive(receivePacket);
            String parse = NetUtils.parse(receivePacket);
            System.out.println(parse);


            String s = scanner.nextLine();
            DatagramPacket sendPacket = NetUtils.getSendPacket(s, "127.0.0.1", 8888);


            socket.send(sendPacket);


        }
    }
}
